
package com.shanghaionstar.user.service;

import android.content.Context;

import com.onstar.cn.api.AccounInfoService;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.common.util.Constants;

import com.onstar.cn.framework.annotation.http.HeadsValue;
import com.onstar.cn.framework.annotation.http.Request;
import com.onstar.cn.framework.mvp.base.core.BaseService;
import com.onstar.cn.framework.network.HttpInjectUtils;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.network.enumtype.HttpAccept;
import com.onstar.cn.framework.network.enumtype.HttpMethod;
import com.onstar.cn.framework.network.enumtype.Language;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.publicService.ChangePassEntity;
import com.onstar.cn.more.response.ChangePassResponse;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.NetConnectUtil;

/**
 * Created by 7828wc on 16/7/1.
 */
public class ChangePasswordService extends BaseService<ChangePassResponse> {
    private Context context;
    private String oldPass, newPass = "";

    public ChangePasswordService(Context context) {
        this.context = context;
    }

    @Override
    @Request(heads = @HeadsValue(accept = HttpAccept.JSON, language = Language.AUTO), method = HttpMethod.PUT)
    public RequestEntity getRequestEntity() {
        RequestEntity requestEntity = NetConnectUtil.getAuthRequestEntity(context);
        AccounInfoService publicService = new AccounInfoService(Constants.CURRENT_SERVER_URL);

        ChangePassEntity codeEntity = new ChangePassEntity();
        codeEntity.setNewPassword(newPass);
        codeEntity.setOldPassword(oldPass);
        publicService.changePass(requestEntity, codeEntity, ApplicationUtil.getInstance().getIdpID());

        requestEntity = HttpInjectUtils.injectHttp(getClass(), "getRequestEntity", requestEntity);
        return requestEntity;
    }

    public void setUpdatePassInfo(String newPass,String oldPass){
        this.oldPass=oldPass;
        this.newPass=newPass;
    }

    @Override
    public ChangePassResponse jsonToBean(String json) {
        if (!CommonUtil.isNull(json))
            return GsonHelper.fromJson(json,ChangePassResponse.class);
        else return null;
    }
}
